<!--
 * @FilePath     : /jquery/demo/200-1.html
 * @Description  : 扩展$.max()和$.min()方法
 * @Date         : 2025-03-26 17:59:24
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-03-26 22:28:07
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <h2>max, min</h2>

    <script src="/library/jquery.min.js"></script>
    <script src="/common/common.js"></script>
    <script>
      // 向 jq 添加扩展
      $.extend({
        max: function () {
          var max = arguments[0]
          for (var i = 0; i < arguments.length; i++) {
            if (max < arguments[i]) {
              max = arguments[i]
            }
          }
          return max
        },
        min: function () {
          var min = arguments[0]
          for (var i = 0; i < arguments.length; i++) {
            if (min > arguments[i]) {
              min = arguments[i]
            }
          }
          return min
        },
      })

      // 调用验证
      console.log($.max(3, 5, 4, 1, 2)) // 5
      console.log($.min(3, 5, 4, 1, 2)) // 1
    </script>
  </body>
</html>
